﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Streambolics
{
    public static class TimeSpanExtensions
    {
        public static TimeSpan Seconds (this int s)
        {
            return new TimeSpan (0, 0, s);
        }

        public static TimeSpan Minutes (this int m)
        {
            return new TimeSpan (0, m, 0);
        }

        public static TimeSpan Hours (this int h)
        {
            return new TimeSpan (h, 0, 0);
        }

        /// <summary>
        ///     Whether the time span has elapsed since a given reference time.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="aReferenceTime"></param>
        /// <returns></returns>
        /// <remarks><para>
        ///     The goal of this function is to be able to write fluently:
        ///     if (aDelay.ElapsedSince (aPointInTime)) ...
        /// </para></remarks>

        public static bool ElapsedSince (this TimeSpan s, DateTime aReferenceTime)
        {
            return aReferenceTime + s < DateTime.Now;
        }

        /// <summary>
        ///     A timestamp in future.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        /// <remarks><para>
        ///     The goal of this function is to be able to write fluently:
        ///     nextEvent = aDelay.FromNow();
        /// </para></remarks>

        public static DateTime FromNow (this TimeSpan s)
        {
            return DateTime.Now + s;
        }
    }

}
